<!--#include file="../nav/admin_top.php" -->
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">溯源管理 - 供应溯源录入</span>
	</div>
</div>
<div class="blockdiv">
	<div class="titlediv">配送批次信息</div>
	<table class="mytable" > 
		<tr>	
			<td class="mylabel"> 配送批次编号：</td>
			<td class="myinfo" style="color:#333333;font-size:14px;" >
				{$rs_source.code}
			</td>
			<td class="mylabel">配送日期：</td>
			<td class="myinfo" style="color:#FF3333;font-size:14px;" > 
				{$rs_source.senddate}
			</td>	
			<td class="mylabel">溯源录入状态：</td>
			<td class="myinfo" style="color:#FF3333;font-size:14px;" > 
				<?PHP
				if($rs_source['pro_flag'] == '0'){
					echo '<div class="noflag">供应溯源</div>';
				}else{
					echo '<div class="yesflag">供应溯源</div>';
				}
				if($rs_source['make_flag'] == '0'){
					echo '<div class="noflag">生产溯源</div>';
				}else{
					echo '<div class="yesflag">生产溯源</div>';
				}
				if($rs_source['send_flag'] == '0'){
					echo '<div class="noflag">配送溯源</div>';
				}else{
					echo '<div class="yesflag">配送溯源</div>';
				}
				?>
			</td>		
		</tr>  
	</table> 
</div>
<style type="text/css">
.sourcetb_out{
width:900px;
border:0px solid #CC3300;
overflow-x:scroll;
margin:10px auto;
}

#searchuser{
width:900px;
border:0px solid #CC3300;
overflow-x:scroll;
margin:10px auto;
text-align:center;

}

table.sourcetb{
border-collapse:collapse;
}
table.sourcetb th{
width:120px;
border: 1px solid #CCCCCC;
background-color: #E2F4C4;
padding: 5px;
text-align: center;
vertical-align: top;
}
table.sourcetb td{
border: 1px solid #CCCCCC;
background-color: #fcfcfc;
padding: 5px;
text-align: center;
vertical-align: top;
}

</style>


<div id="div_tabs">
	<!--	<ul>
			<li><a href="#div_source_vege"><span>菜品溯源</span></a></li>
			<li><a href="#div_source_user"><span>配送溯源</span></a></li>
			<li><a href="#div_source_one"><span>模拟会员溯源查询</span></a></li>
		</ul>
	-->	
	
	
	<div class="blockdiv">
		<div class="titlediv">菜品溯源</div>
	
		<div id="div_source_vege">
			<div class="sourcetb_out" >
				<div style="width:<?PHP echo (count($pro_fields) + count($make_fields)+11)*132+20; ?>px">
					<table class="sourcetb" >
						<tr>
							<th>品类</th>
							<th>品名</th>
							<th>基地</th>
							<th>海拔（米）</th>
							<th>采收时间</th>
							<th>采收人员</th>
							<th>采收质检员</th>
							<th>空运时间</th>
							<?PHP
							foreach($pro_fields as $k=>$v){
								echo '<th>'.$v['field_name'].'</th>';
							}
							?>
							<th>入库时间</th>
							<th>加工包装时间</th>
							<th>加工质检员</th>
							<?PHP
							foreach($make_fields as $k=>$v){
								echo '<th>'.$v['field_name'].'</th>';
							}
							?>
						</tr>
						<?PHP
						foreach($rs_source_vege as $val){
							echo '<tr >';
							echo '	<td >'.$val['vegetype_name'].'</td>';
							echo '	<td >'.$val['vege_name'].'</td>';
							echo '	<td >'.$val['pro_base'].'</td>';
							echo '	<td >'.$val['pro_height'].'</td>';
							echo '	<td >'.$val['pro_picktime'].'</td>';
							echo '	<td >'.$val['pro_pickman'].'</td>';
							echo '	<td >'.$val['pro_testman'].'</td>';
							echo '	<td >'.$val['pro_plantime'].'</td>';
							foreach($pro_fields as $k=>$v){
								echo '<td >'.$val[$k].'</td>';
							}
							echo '	<td >'.$val['make_intime'].'</td>';
							echo '	<td >'.$val['make_time'].'</td>';
							echo '	<td >'.$val['make_testman'].'</td>';
							foreach($make_fields as $k=>$v){
								echo '<td >'.$val[$k].'</td>';
							}
							echo '</tr>';
						}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	
	
	<div class="blockdiv">
		<div class="titlediv">配送溯源</div>
		
		<div id="div_source_user">
			<div class="sourcetb_out" >
				<div style="width:<?PHP echo (count($send_fields)+4)*132+20; ?>px">
					<table class="sourcetb"  >
						<tr>
							<th>会员姓名</th>
							<th>会员编号</th>
							<th>出库时间</th>
							<th>配送人员</th>
							<?PHP
							foreach($send_fields as $k=>$v){
								echo '<th>'.$v['field_name'].'</th>';
							}
							?>
						</tr>
						<?PHP
						foreach($rs_source_user as $val){
							echo '<tr >';
							echo '	<td >'.$val['name'].'</td>';
							echo '	<td >'.$val['username'].'</td>';
							echo '	<td >'.$val['send_outtime'].'</td>';
							echo '	<td >'.$val['send_man'].'</td>';
							foreach($send_fields as $k=>$v){
								echo '<td >'.$val[$k].'</td>';
							}
							echo '</tr>';
						}
						?>
					</table>
				</div>
			</div>
		</div>
	</div>
	
	
	<div class="blockdiv">
		<div class="titlediv">模拟会员溯源查询</div>
		
		<div id="div_source_one">
			<div style="margin:10px auto">
				<div style="text-align:left;margin:30px">
					请选择会员：
					<select class="textBox" id="slt_user_id">
						<?PHP
						foreach($rs_source_user as $val){
							echo '<option value="'.$val['user_id'].'">'.$val['username'].'('.$val['name'].')</option>';
						}
						?>
					</select>
					<button onclick="fnSearchByUser()">查询</button>
				</div>
				<div id="searchuser">
					
				</div>
			</div>
		</div>
	</div>
	
</div>	 
<div  class="button_div">
		<button onclick="fnReturn()">返 回</button>
</div> 
<script type="text/javascript">
var rs_source = {json_encode($rs_source)};
var rs_source_user = {json_encode($rs_source_user)};
var rs_source_vege = {json_encode($rs_source_vege)};
var pro_fields = {json_encode($pro_fields)};
var make_fields = {json_encode($make_fields)};
var send_fields = {json_encode($send_fields)};

var url_return = '/admin_source_search/index';
$().ready(function(){
	showLoading();
	//o2js.build('o2tabs');
	//$('#div_tabs').tabs();
//	$('#div_tabs').triggerTab(0);
});
function fnSearchByUser(){
	var user_id = $('#slt_user_id').val();
	var sendpi_id = rs_source.sendpi_id;
	if(!user_id){
		$('#searchuser').html('暂无信息');
		return false;
	}
	$('button').attr('disabled','disabled');
	$('#searchuser').html('加载中......');
	$.post(
		'/admin_source_search/loadUserSource',
		{
			user_id:user_id,
			sendpi_id:sendpi_id
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success=='1'){
				fnBuildUserSource(ok.results);
			}else{
				$('#searchuser').html('暂无信息');
			}
			$('button').attr('disabled','');
		}
	);
}
function fnBuildUserSource(rs){
	var totallength = pro_fields.length + make_fields.length + send_fields.length ;
	totallength = ((totallength+13)*132)+20;
	var str = '<div style="width:'+totallength+'px">';
	str += '<table class="sourcetb" >';
	str += '	<tr>';
	str += '		<th>品类</th>';
	str += '		<th>品名</th>';
	str += '		<th>基地</th>';
	str += '		<th>海拔（米）</th>';
	str += '		<th>采收时间</th>';
	str += '		<th>采收人员</th>';
	str += '		<th>采收质检员</th>';
	str += '		<th>空运时间</th>';
	for(var kk=0; kk<pro_fields.length; kk++){
		str += '		<th>'+pro_fields[kk].field_name+'</th>';
	}
	str += '				<th>入库时间</th>';
	str += '				<th>加工包装时间</th>';
	str += '				<th>加工质检员</th>';
	for(var kk=0; kk<make_fields.length; kk++){
		str += '		<th>'+make_fields[kk].field_name+'</th>';
	}
	str += '				<th>出库时间</th>';
	str += '				<th>配送人员</th>';
	for(var kk=0; kk<send_fields.length; kk++){
		str += '		<th>'+send_fields[kk].field_name+'</th>';
	}
	str += '			</tr>';

	for(var i=0; i<rs.length; i++){
		var obj = rs[i];
		str += '<tr>';
		str += '<td>'+obj.vegetype_name+'</td>';
		str += '<td>'+obj.vege_name+'</td>';
		str += '<td>'+obj.pro_base+'</td>';
		str += '<td>'+obj.pro_height+'</td>';
		str += '<td>'+obj.pro_picktime+'</td>';
		str += '<td>'+obj.pro_pickman+'</td>';
		str += '<td>'+obj.pro_testman+'</td>';
		str += '<td>'+obj.pro_plantime+'</td>';
		for(var kk=0; kk<pro_fields.length; kk++){
			str += '		<td>'+obj[pro_fields[kk].id]+'</th>';
		}
		str += '<td>'+obj.make_intime+'</td>';
		str += '<td>'+obj.make_time+'</td>';
		str += '<td>'+obj.make_testman+'</td>';
		for(var kk=0; kk<make_fields.length; kk++){
			str += '		<td>'+obj[make_fields[kk].id]+'</th>';
		}
		str += '<td>'+obj.send_outtime+'</td>';
		str += '<td>'+obj.send_man+'</td>';
		for(var kk=0; kk<send_fields.length; kk++){
			str += '		<td>'+obj[send_fields[kk].id]+'</th>';
		}
		str += '</tr>';
	}
	str += '</table>';
	str += '</div>';
	$('#searchuser').html('');
	$('#searchuser').html(str);
}
function fnReturn(){
	jumpTo(url_return);
}
</script>
<!--#include file="../nav/admin_bottom.php" -->